/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.statemachine.figure;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Image;

import com.cea.papyrus.core.figures.IconFigure;
import com.cea.papyrus.core.utils.Debug;

/**
 * A figure used as a basis for State, Pseudostate and FinalState in state machine diagrams.
 * 
 * @author David Servat
 * @since 16 mar. 07
 */
public class PseudostateFigure extends IconFigure{

	/**
	 * Debug channel.
	 */
	private int channel = 501;

	/**
	 * create an icon figure.
	 * 
	 * @param numberNode is used to spcify a unique identfier tha t is associated to the image thanks
	 * to the graphNode.hashCode()
	 * @param image the image (GIF) that we want to see
	 */
	public PseudostateFigure(Image image, int numberNode){ 
		super(image, numberNode);

		Debug.debug(this, "Call PseudostateFigure(Image image, int numberNode)", channel);
	}

	/**
	 * This method is overriden to get rid of the automatic scaling performed by the superclass.
	 * The code is copied from the super.super class
	 */
	@Override
	public void setBounds(Rectangle rect){
		Debug.debug(this, "Call PseudostateFigure.setBounds(Rectangle rect)", channel);

		//code copied from the super.super class
		int x = bounds.x,
		y = bounds.y;

		boolean resize = (rect.width != bounds.width) || (rect.height != bounds.height),
		translate = (rect.x != x) || (rect.y != y);

		if ((resize || translate) && isVisible())
			erase();
		if (translate) {
			int dx = rect.x - x;
			int dy = rect.y - y;
			primTranslate(dx, dy);
		}

		bounds.width = rect.width;
		bounds.height = rect.height;

		if (translate || resize) {
			if (resize)
				invalidate();
			fireFigureMoved();
			repaint();
		}
	}
}
